package com.pure.database.greendao

import android.content.Context
import com.pure.database.gen.DaoMaster
import com.pure.database.gen.DaoMaster.DevOpenHelper
import com.pure.database.gen.GDOrderDao
import com.pure.database.gen.GDUserDao
import com.pure.database.greendao.migrate.MigrationHelper
import com.pure.database.greendao.migrate.MigrationHelper.ReCreateAllTableListener
import org.greenrobot.greendao.database.Database

/**
 * FileName : MySQLiteOpenHelper
 * Author : luqihua
 * Date : 2025/3/20
 * Desc : 自定义升级处理
 **/

class MySQLiteOpenHelper(context: Context, name: String) : DevOpenHelper(context, name) {
    override fun onUpgrade(db: Database?, oldVersion: Int, newVersion: Int) {
        MigrationHelper.migrate(db, object : ReCreateAllTableListener {
            override fun onCreateAllTables(db: Database, ifNotExists: Boolean) {
                DaoMaster.createAllTables(db, ifNotExists)
            }

            override fun onDropAllTables(db: Database, ifExists: Boolean) {
                DaoMaster.dropAllTables(db, ifExists)
            }
        }, GDUserDao::class.java, GDOrderDao::class.java)
    }
}